package com.nursing.controller.nurse;

import com.github.pagehelper.PageInfo;
import com.nursing.bean.Admin;
import com.nursing.bean.Nurse;
import com.nursing.model.Result;
import com.nursing.model.vo.admin.AdminLoginVo;
import com.nursing.service.NurseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nurse")
public class NurseUserController {

    private final NurseService service;

    public NurseUserController(NurseService service) {
        this.service = service;
    }

    @GetMapping("/list")
    public Result<PageInfo<Nurse>> list(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int size) {
        return Result.success(service.list(page, size));
    }

    @PostMapping("/add")
    public Result<Nurse> add(@RequestBody Nurse nurse) {
        service.addNurse(nurse);
        return Result.success("添加成功");
    }

    @PostMapping("/update")
    public Result<Nurse> update(@RequestBody Nurse nurse) {
        service.updateNurse(nurse);
        return Result.success("修改成功");
    }

    @DeleteMapping("/delete")
    public Result<Nurse> delete(@RequestParam Integer id) {
        service.deleteNurse(id);
        return Result.success("删除成功");
    }


    @PostMapping("/login")
    @ApiOperation("护工登录")
    public Result<Nurse> Login(@RequestBody AdminLoginVo adminLoginVo){
        String username = adminLoginVo.getUsername();
        String password = adminLoginVo.getPassword();
        Nurse nurse = service.login(username,password);
        if(nurse == null){
            return Result.fail(400,"用户名或密码错误");
        }
        return Result.success("登录成功",nurse);
    }

    @GetMapping("/getNurseById")
    public Result<Nurse> getNurseById(@RequestParam Integer id) {
        return Result.success(service.getNurseById(id));
    }

//    修改密码
    @PostMapping("/changePassword")
    public Result<Nurse> changePassword(@RequestBody Nurse nurse){
         service.changePassword(nurse);
        return Result.success("修改成功");
    }
}
